<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%
    String namedid = "0";
	String strSessionk = (String) request.getSession().getAttribute("namet");
	System.out.println("JSP:" + strSessionk);
	namedid = strSessionk;
%>
<title><%=strSessionk%>评论的博客</title>
<style type="text/css">
body {
	text-align: center;
}

a {
	text-decoration: none;
	color: black;
}
a:hover {
    color: red;
}
.idsize{
    width: 70px;
    height: 70px;
}
.bkksize{
    width: 700px;
}
table{
    position: relative;
	left: 70px;
	top: 110px;
}
</style>
</head>
<body onmousemove="pos()">
	<%!
	    private static final String JDBC_URL = "jdbc:mysql://localhost:3309/blog?useUnicode=true&characterEncoding=utf8";
	    private static final String DB_USER = "root";
	    private static final String DB_PWD = "ZLWL";
	    int bokeshul = 0;
	    Map<String, String> hashMaph = new HashMap<String, String>();
	%>
	<%
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		Connection connph;
		try {
			connph = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
			Statement stmtph = connph.createStatement();
			System.out.println("***********************************");
			String sqll = "select id from user_zc where name = '" + namedid + "'";   //读取用户的ID
			ResultSet rsl = stmtph.executeQuery(sqll);
			int setnamedis = 0;
			while (rsl.next()) {
				int getnamedis = rsl.getInt(1);
				setnamedis = getnamedis;
			}
			System.out.println("user_zc id:" + setnamedis);
			String sqlcountbbk = "select count(author_id) total from blog";   //计算博客数量
			ResultSet rscountbbk = stmtph.executeQuery(sqlcountbbk);
			int setcountbbk = 0;
			while (rscountbbk.next()) {
				int getcountbbk = rscountbbk.getInt(1);
				setcountbbk = getcountbbk;
			}
			System.out.println("setcountbbk:" + setcountbbk);
			String sqlcountbbks = "select ping_id = " + setnamedis + " from review";    //读取该用户的评论情况
			ResultSet rscountbbks = stmtph.executeQuery(sqlcountbbks);
			int bbks = 1;
			Map<String, String> hashMapbbks = new HashMap<String, String>();
			while (rscountbbks.next()) {
				hashMapbbks.put("ping_id" + bbks, rscountbbks.getString(1));
				System.out.println("ping_id" + bbks + ":" + hashMapbbks.get("ping_id" + bbks));
				bbks ++;
			}
			int bbkkss = 1;
			boolean shifouabc = true;
			while(bbkkss < bbks){
				System.out.println("ping_id" + bbkkss + ":" + hashMapbbks.get("ping_id" + bbkkss));   //判断用户有无评论
				if(!hashMapbbks.get("ping_id" + bbkkss).equals("0")){
					shifouabc = false;
				}
				bbkkss ++;
			}
			System.out.println("shifouabc:" + shifouabc);
			if(shifouabc){                                                                   //如果用户没有评论就跳到其他界面
				response.sendRedirect("wumeiyouppl.html");return;
			}
			System.out.println("***********************************");
			String sqlph = "select bei_id from review where reviewer = '" + strSessionk + "'";
			ResultSet rsph = stmtph.executeQuery(sqlph);
			int i = 1;
			while (rsph.next()) {
				hashMaph.put("bei_idy" + i, rsph.getString("bei_id"));
	     		System.out.println("bei_idy" + i + ":" + hashMaph.get("bei_idy" + i));
			    i ++;
			}
			System.out.println("i:" + i);
			int j = 2;
			int l =1;
			int m = 0;
			boolean iscf1 = true;
			while(j < i){
			int k = j;
			while(k < i){
				if(hashMaph.get("bei_idy" + l).equals(hashMaph.get("bei_idy" + k))){
					iscf1 = false;
				}
				System.out.println("bei_idy" + l + ":" + hashMaph.get("bei_idy" + k));
				k ++;
			}
			System.out.println("iscf1:" + iscf1);
			if(iscf1){
				m ++;
				hashMaph.put("bei_id" + m, hashMaph.get("bei_idy" + l));
			}
			System.out.println("bei_id" + m + ":" + hashMaph.get("bei_id" + m));
			j ++;
			l ++;
			iscf1 = true;
			System.out.println("****************************");
			}
			m ++;
			hashMaph.put("bei_id" + m, hashMaph.get("bei_idy" + (i - 1)));
			System.out.println("bei_id" + m + ":" + hashMaph.get("bei_id" + m));
			System.out.println("############################");
			int n =1;
			while(n <= m){
				System.out.println("bei_id" + n + ":" + hashMaph.get("bei_id" + n));
				n ++;
			}
			System.out.println("############################");
			for(int p = 1; p < n; p ++){
			    System.out.println("turn:" + p);
			for(int o = p; o < n; o ++){
			    System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
				System.out.println("bei_id" + p + ":" + hashMaph.get("bei_id" + p));
				System.out.println("bei_id" + o + ":" + hashMaph.get("bei_id" + o));
			    System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
				if(Integer.parseInt(hashMaph.get("bei_id" + p)) > Integer.parseInt(hashMaph.get("bei_id" + o))){
					String lins =  hashMaph.get("bei_id" + p);
					hashMaph.put("bei_id" + p, hashMaph.get("bei_id" + o));
					hashMaph.put("bei_id" + o, lins);
				}
				System.out.println("bei_id" + p + ":" + hashMaph.get("bei_id" + p));
				System.out.println("bei_id" + o + ":" + hashMaph.get("bei_id" + o));
			    System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			}
			}
			System.out.println("############################");
			int q =1;
			while(q <= m){
				System.out.println("bei_id" + q + ":" + hashMaph.get("bei_id" + q));
				q ++;
			}
			System.out.println("############################");
			int t = 1;
			int r = 1;
			while(t <= m){
			String sqlm = "select * from blog where id = " + hashMaph.get("bei_id" + t);
			ResultSet rsps = stmtph.executeQuery(sqlm);
			while (rsps.next()) {
				hashMaph.put("id" + r, rsps.getString("id"));
	     		System.out.println("blog id" + r + ":" + hashMaph.get("id" + r));
				hashMaph.put("title" + r, rsps.getString("title"));
	     		System.out.println("blog title" + r + ":" + hashMaph.get("title" + r));
			    r ++;
			}
			t ++;
			rsps.close();
			}
			System.out.println("****************************************");
			response.getWriter().append("<table border='1' id='cs'>");
			response.getWriter().append("<tr>");
			response.getWriter().append("<th class='idsize'>ID</th>");
			response.getWriter().append("<th class='bkksize'>博客</th>");
			response.getWriter().append("</tr>");
			response.getWriter().append("</table>");
			int u = 1;
			while(u <= m) {
				response.getWriter().append("<table border='1' id='" + hashMaph.get("id" + u) + "'>");
				response.getWriter().append("<tr>");
				response.getWriter().append("<th class='idsize'>");
				response.getWriter().append("<a onclick='wdcsid()'>");
				response.getWriter().append(hashMaph.get("id" + u));
				response.getWriter().append("</a>");
				response.getWriter().append("</th>");
				response.getWriter().append("<th class='bkksize'>");
				response.getWriter().append("<a onclick='wdcsid()'>");
				response.getWriter().append(hashMaph.get("title" + u));
				response.getWriter().append("</a>");
				response.getWriter().append("</th>");
				response.getWriter().append("</tr>");
				response.getWriter().append("</table>");
				System.out.println("blog id" + u + ":" + hashMaph.get("id" + u));
				System.out.println("blog title" + u + ":" + hashMaph.get("title" + u));
				u ++;
			}
			rsph.close();
			rscountbbks.close();
			rscountbbk.close();
			rsl.close();
			stmtph.close();
			connph.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	%>
	<br><br><br><br><br><br><br><br><br><br>
	<form method="post" name="pasorms" action="blogpage.jsp">
		<input type='hidden' name="csflid">
		<input type='hidden' name="csflids">
	</form>
	<!--  
	<span class="div djcx2">鼠标当前在:</span>
	<span id="show" class="div djcx4"></span>
	-->
	<script type="text/javascript">
	var diffiernumt = 0;
	function fnGetTable(oEl) {
		try {
			while (null != oEl && oEl.tagName != "TABLE") {
				oEl = oEl.parentElement;
			}
			return oEl;
		} catch (e) {
			return null;
		}
	}
	function pos() {
		try {
			oElement = document.elementFromPoint(event.x, event.y);
			oElement = fnGetTable(oElement);
			if (oElement.tagName == "TABLE")
				//show.innerText = oElement.id;
			    diffiernumt = oElement.id;
		} catch (e) {
		}
	}
	function setinputmn(csflid,csflids){
		document.pasorms.csflid.value = csflid;
		document.pasorms.csflids.value = csflids;
	    document.pasorms.submit();
	}
	function wdcsid(){
		setinputmn(diffiernumt,"mdzz");
	}
	</script>
</body>
</html>